<template>
  <div class="common-layout">
        <el-container>
            <el-header>Forum Register</el-header>
            <el-main>
              <el-card class="box-card">
                <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
                    <el-form-item label="用户名">
                      <el-input type="text" v-model="ruleForm.userName" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                      <el-input type="password" v-model="ruleForm.passWord" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码">
                      <el-input v-model="ruleForm.verfyCode"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="submitForm('ruleForm')">注册</el-button>
                    </el-form-item>
                </el-form>
              </el-card>
            </el-main>
            <el-footer>
                  <el-link type="primary" class="footer-el-link">使用条件</el-link>
                  <el-link type="primary" class="footer-el-link">帮助中心</el-link>
                  <el-link type="primary" class="footer-el-link">隐私声明</el-link>
              <div class="footer-el-link-div">版权所有 © 1996-2021，LIUYI Forum 旗舰公司或其附属机构</div>  
            </el-footer>
        </el-container>
  </div>
</template>

<script>
export default {
  name: 'Register',
  data() {
      var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('年龄不能为空'));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value < 18) {
              callback(new Error('必须年满18岁'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          userName: '',
          passWord: '',
          verfyCode: '',
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          age: [
            { validator: checkAge, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>

/** 
  样式构造
*/
<style scoped>
.el-header, .el-footer{
    /* background-color: #B3C0D1; */
    color: #333;
    text-align: center;
    line-height: 60px;
    font-size: 22px;
    margin-right: 120px;
    margin-top: 50px;
  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }

  .el-main {
    /* background-color: #E9EEF3; */
    color: #333;
    text-align: center;
    line-height: 75vh;
    margin-right: 120px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    margin-top: 50px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
  /**.box-card 卡片样式 */
  .box-card {
    margin: 3% auto;
    margin-top: 2%;
    width: 35%;
  }
   /**.box-card 卡片样式 */

  /** footer 样式调整 */
  .footer-el-link {
    margin: 0 20px;
  }
 .footer-el-link-div {
      font-size: 16px;
      height: 10px;
      line-height: 10px;
}
 /** footer 样式调整 */

 /**.reg-button 创建账号按钮 */
 .reg-button {
   width: 100%;
 }
</style>